<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline filter">
      <!--<el-form-item label="客户名称">
        <el-select  @change="fsiteNoQueChange" v-model="listQuery.fsiteNo" clearable filterable class="filter-item" placeholder="请选择客户名称">
          <el-option
            v-for="item in getListfsiteNo"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>-->
      <div>
      <el-form-item label="存放地点">
        <div style="display:flex;justify-content:flex-start;align-items:center">
          <el-select style="display: inline-block" clearable filterable v-model="listQuery.fpointNo" class="filter-item" placeholder="请选择存放地点">
            <el-option
              v-for="item in getListfpointNo"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <i class="el-icon-search selectI" @click="searchDialoglab('search')"/>
        </div>
      </el-form-item>
      <el-form-item label="存放位置">
        <el-input
          v-model="listQuery.fpointSize"
          clearable
          class="filter-item"
          placeholder="请输入存放位置"
        />
      </el-form-item>
      <!--<el-form-item label="设备类型">
        <el-select v-model="listQuery.fequipmenttype" filterable clearable class="filter-item" placeholder="请选择设备分类">
          <el-option
            v-for="item in getListfequipmenttype"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>-->
        <!-- <el-option
            v-for="item in fbillstateOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
      </el-form-item> -->
      <el-form-item label="固定资产码">
        <el-input
          v-model="listQuery.fequipmentbarcode"
          clearable
          class="filter-item"
          placeholder="请输入固定资产码"
        />
      </el-form-item>
        <el-form-item label="序列号">
        <el-input
          v-model="listQuery.fmacno"
          clearable
          class="filter-item"
          placeholder="请输入序列号"
        />
      </el-form-item>
      </div>
      <div>
          <el-form-item label="设备标签">
        <el-input
          v-model="listQuery.fequipmenttag"
          clearable
          class="filter-item"
          placeholder="请输入设备标签"
        />
      </el-form-item>
      <el-form-item style="margin-left: 14px" label="设备状态">
        <el-select v-model="listQuery.fstate" clearable filterable placeholder="请选择设备状态">
          <el-option
            v-for="item in fstateOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          round
          size="medium"
          class="filter-item"
         :style="{background:buttonColor.lookup,color:buttonColor.color}"
          @click="handleFilter"
        >查找</el-button
        >
        <el-button
          round
          size="medium"
          class="filter-item"
          :style="{background:buttonColor.add,color:buttonColor.color}"
          @click="handleCreate"
        >添加</el-button
        >
         <el-button
          round
          size="medium"
          :style="{ background: buttonColor.import, color: buttonColor.color }"
          @click="handleUpload"
          >导入</el-button
        >
      </el-form-item>
      </div>
    </el-form>

    <!-- 查询结果 -->
    <el-table
      :height="buttonColor.clientHeightTwo"
      v-loading="listLoading"
      :data="list"
      :header-cell-style="tableColor"
      stripe
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
       <el-table-column align="center" label="操作" class-name="small-padding" :width="buttonColor.operationThree">
        <template slot-scope="scope">
          <div class="operationButton">
            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="handleUpdate(scope.row)">
            <img src="../../../public/images/edit.png" />
            编辑
          </div>
          <div :style="{color:buttonColor.delete,cursor:'pointer'}" @click="handleDelete(scope.row)">
            <img src="../../../public/images/del.png" />
            删除
          </div>
           <div :style="{color:buttonColor.print,cursor:'pointer'}">
            <img src="../../../public/images/print.png" />
            打印
          </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        :index="indexMethod"
        align="center"
        :width="buttonColor.line"
        label="序"
        type="index"
      />
      <el-table-column :width="buttonColor.name" :formatter="formatfsiteNo" align="left" label="客户名称" prop="fsiteNo" />
      <el-table-column :formatter="formatfpointNo" align="left" label="存放地点" prop="fpointNo" />
      <el-table-column align="left" label="存放位置" prop="fpointSize" />
      <el-table-column
        :width="buttonColor.billno"
        align="left"
        label="固定资产码"
        prop="fequipmentbarcode"
      />
      <el-table-column :width="buttonColor.billno" align="left" label="序列号" prop="fmacno" />
      <el-table-column align="left" label="设备标签" prop="fequipmenttag" />
      <!-- <el-table-column :formatter="formatfequipmenttype" align="center" label="设备类型" prop="fequipmenttype" /> -->
      <el-table-column width="100" align="left" label="排插MAC" prop="flinkmac" />
      <el-table-column align="left" label="标识符" prop="flinkmark" />
      <!-- <el-table-column align="center" label="状态" prop="fstate" >
        <template slot-scope="scope">
          <el-tag effect="dark" type='success' v-if="scope.row.fstate===0">{{ scope.row.fstate | statusFilter }}</el-tag>
          <el-tag effect="dark" type='warning' v-else-if="scope.row.fstate===1">{{ scope.row.fstate | statusFilter }}</el-tag>
          <el-tag effect="dark" type='danger' v-else>{{ scope.row.fstate | statusFilter }}</el-tag>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      width="75%"
    >
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="90px"
      >

        <el-row>
          <el-col :span="8">
            <el-form-item class="required" label="客户名称" prop="fsiteNo">
              <el-select :disabled='true' @change="fsiteNoChange" v-model="dataForm.fsiteNo" clearable filterable class="filter-item" placeholder="请选择用户名称">
                <el-option
                  v-for="item in getListfsiteNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-if="this.$store.state.user.fsiteLevel==3"
              label="存放地点"
              prop="fpointNo"
            >
              <div style="display:flex;justify-content:flex-start;align-items:center">
                <el-select style="display: inline-block" clearable filterable v-model="dataForm.fpointNo" class="filter-item" placeholder="请选择存放地点">
                  <el-option
                    v-for="item in getListfpointNo"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"/>
                </el-select>
                <i class="el-icon-search selectI" @click="searchDialoglab('add')"/>
              </div>
            </el-form-item>
            <el-form-item
              v-else
              label="存放地点"
              prop="fpointNo"
            >
              <div style="display:flex;justify-content:flex-start;align-items:center">
                <el-select style="display: inline-block" clearable filterable v-model="dataForm.fpointNo" class="filter-item" placeholder="请选择存放地点">
                  <el-option
                    v-for="item in getListfpointNoAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"/>
                </el-select>
                <i class="el-icon-search selectI" @click="searchDialoglab('add')"/>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存放位置" prop="fpointSize">
              <el-input v-model="dataForm.fpointSize" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item class="required" label="设备编号" prop="feuipmentid">
              <div v-if="dialogStatus=='create'" style="display:flex;justify-content:flex-start;align-items:center">
                <el-input v-model="dataForm.feuipmentid" style="display: inline-block" />
                <i class="el-icon-search selectI" @click="searchDialogEequipmentInfo()"/>
              </div>
              <div v-else style="display:flex;justify-content:flex-start;align-items:center">
                <el-input disabled v-model="dataForm.feuipmentid" style="display: inline-block" />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备标签" prop="fequipmenttag">
              <el-input v-model="dataForm.fequipmenttag" />
            </el-form-item>
          </el-col>
          <!--<el-col :span="8">
            <el-form-item label="设备类型" prop="fequipmenttype">
              <el-select :disabled="true" v-model="dataForm.fequipmenttype" filterable clearable class="filter-item" placeholder="请选择设备分类">
                <el-option
                  v-for="item in getListfequipmenttype"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item class="required" label="固定资产码" prop="fequipmentbarcode">
              <el-input :disabled='true' v-model="dataForm.fequipmentbarcode" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="型号" prop="fspec">
              <el-input :disabled="true" v-model="dataForm.fspec" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item class="required" label="设备状态" prop="fstate">
              <el-select v-model="dataForm.fstate" clearable filterable placeholder="请选择设备状态">
                <el-option
                  v-for="item in fstateOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="面板颜色" prop="fcolor">
              <el-input v-model="dataForm.fcolor" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="安装日期" prop="finstalldate">
              <el-date-picker v-model="dataForm.finstalldate" type="date" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="下次保养" prop="fmaintaindate">
              <el-date-picker v-model="dataForm.fmaintaindate" type="date" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最后维修" prop="frepairdate">
              <el-date-picker v-model="dataForm.frepairdate" type="date" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="设备原值" prop="fbuyprice">
              <el-input v-model="dataForm.fbuyprice" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="折旧方法" prop="foldway">
              <el-select clearable filterable v-model="dataForm.foldway" placeholder="请选择">
                <el-option
                  v-for="item in foldwayOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="累加折旧" prop="foldmoney">
              <el-input v-model="dataForm.foldmoney" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="净残值率" prop="flastrate">
              <el-input v-model="dataForm.flastrate" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="净值" prop="flastmoney">
              <el-input v-model="dataForm.flastmoney" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报废日期" prop="flosdate">
              <el-date-picker v-model="dataForm.flosdate" type="date" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="16">
            <el-form-item class="text" style="width:94%" label="视频URL" prop="fvideourl">
              <el-input v-model="dataForm.fvideourl" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="序列号" prop="fmacno">
              <el-input v-model="dataForm.fmacno" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="供应商" prop="fsupno">
              <el-input v-model="dataForm.fsupno" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="排插MAC" prop="flinkmac">
              <el-input v-model="dataForm.flinkmac" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标识符" prop="flinkmark">
              <el-input v-model="dataForm.flinkmark" />
            </el-form-item>
          </el-col>
        </el-row>
         <el-row>
          <el-col :span="8">
            <el-form-item label="TCP/IP" prop="fip">
              <el-input v-model="dataForm.fip" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="PORT" prop="fport">
              <el-input v-model="dataForm.fport" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible = false">取消</el-button>
        <el-button
          round
          v-if="dialogStatus == 'create'"
         :style="{background:buttonColor.confirm,color:buttonColor.color}"
          @click="createData"
        >确定</el-button
        >
        <el-button round v-else :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="updateData">确定</el-button>
      </div>
    </el-dialog>

    <!-- 设备搜索弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="searchVisible"
      top="5vh"
    >
     <template slot="title">
        <div :style="titleColor">搜索</div>
      </template>
      <el-form :inline="true" class="demo-form-inline">
        <!--<el-form-item label="设备编号">
          <el-input
            v-model="listQuerySearch.fequipmentno"
            clearable
            class="filter-item"
            style="width: 150px"
            placeholder="请输入设备编号"
          />
        </el-form-item>-->
        <el-form-item label="设备编号" prop="fequipmentno">
          <div v-if="dialogStatus=='create'" style="display:flex;justify-content:flex-start;align-items:center">
            <el-input v-model="dataForm.fequipmentno" style="display: inline-block" />
            <i class="el-icon-search selectI" @click="searchDialogEequipmentInfo()"/>
          </div>
          <div v-else style="display:flex;justify-content:flex-start;align-items:center">
            <el-input disabled v-model="dataForm.fequipmentno" style="display: inline-block" />
          </div>
        </el-form-item>
        <el-form-item label="设备名称">
          <el-input
            v-model="listQuerySearch.fequipmentname"
            clearable
            class="filter-item"
            placeholder="请输入设备名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            round
            size="medium"
            class="filter-item"
            :style="{background:buttonColor.lookup,color:buttonColor.color}"
            @click="searchFilter"
          >查找</el-button
          >
        </el-form-item>
      </el-form>

      <!-- 查询结果 -->
      <el-table
        v-loading="listLoadingSearch"
        :data="searchList"
        :header-cell-style="tableColor"
        stripe
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
        height="300"
      >
        <el-table-column align="center" label="设备编号" prop="fequipmentno" />
        <el-table-column align="center" label="设备名称" prop="fequipmentname" />
        <el-table-column
          align="center"
          label="选择"
          class-name="small-padding"
        >
          <template slot-scope="scope">
            <el-button
              :style="{background:buttonColor.confirm,color:buttonColor.color}"
              round
              size="small"
              class="button-margin"
              @click="searchData(scope.row)"
            >确定</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalSearch > 0"
        :total="totalSearch"
        :page.sync="listQuerySearch.page"
        :limit.sync="listQuerySearch.limit"
        style="padding:14px 10px !important"
        @pagination="getSearchList"
      />
    </el-dialog>
    <!-- 地点搜索弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="searchVisiblelab"
      :before-close="handleClose"
      top="5vh"
    >
     <template slot="title">
        <div :style="titleColor">搜索</div>
      </template>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="预约地点">
          <el-input
            v-model="listQuerySearchlab.fpointName"
            clearable
            class="filter-item"
            style="width: 150px"
            placeholder="请输入预约地点"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            round
            size="medium"
            class="filter-item"
            :style="{background:buttonColor.lookup,color:buttonColor.color}"
            @click="searchFilterlab"
          >查找</el-button
          >
        </el-form-item>
      </el-form>

      <!-- 查询结果 -->
      <el-table
        v-loading="listLoadingSearchlab"
        :data="searchListlab"
        :header-cell-style="tableColor"
        stripe
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
        height="300"
      >
        <el-table-column align="center" label="预约地点" prop="fpointName" />
        <el-table-column
          align="center"
          label="选择"
          class-name="small-padding"
        >
          <template slot-scope="scope">
            <el-button
             :style="{background:buttonColor.confirm,color:buttonColor.color}"
              round
              size="small"
              class="button-margin"
              @click="searchDatalab(scope.row)"
            >确定</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalSearchlab > 0"
        :total="totalSearchlab"
        :page.sync="listQuerySearchlab.page"
        :limit.sync="listQuerySearchlab.limit"
        style="padding:14px 10px !important"
        @pagination="getSearchListlabPage"
      />
    </el-dialog>
      <!-- 导出弹窗 -->
    <el-dialog
      width="auto"
      :close-on-click-modal="false"
      :visible.sync="uploadVisible"
    >
      <template slot="title">
        <div :style="exportColor">设备台账</div>
      </template>
      <div
        style="
          width: 300px;
          height: 200px;
          display: flex;
          flex-direction: column;
          align-items: center;
        "
      >
        <el-upload
          :on-success="uploadFileSuccess"
          :headers="headers"
          :action="uploadPath2"
          :data="{ tableName: 'Import_i_ts_qualityEqtInv1' }"
          :show-file-list="false"
          class="filter-item"
          style="margin-top: 20px"
          accept=".xlsx"
        >
          <el-button
            round
            size="medium"
            icon="el-icon-upload"
            :style="{
              background: buttonColor.import,
              color: buttonColor.color,
            }"
            >导入</el-button
          >
        </el-upload>
        <div style="margin-top: 30px; text-decoration: underline">
          <a :href="downUrl" style="color: blue">模板文件下载</a>
        </div>
      </div>
    </el-dialog>

    <labDialog :searchVisiblelab.sync="searchVisiblelab" :fsiteNo.sync="labDialogFsiteNo" :tableColor="tableColor" @labDialog="labDialogValue" />
    <equipmentInfoDialog :equipmentInfoVisible.sync="equipmentInfoVisible" :tableColor="tableColor" @equipmentInfoDialog="equipmentInfoDialogValue" />
  </div>
</template>

<style>
.button-margin {
  margin: 2px 0px;
}
.el-button + .el-button {
  margin-left: 1px;
}
</style>

<script>
import {
  listequipmentInv,
  createequipmentInv,
  updateequipmentInv,
  deleteequipmentInv,
  uploadPath
} from '@/api/equipmentInv'
import { fsiteOptionsByLevel,getListArea, getFequipmentbarcode,getPointOptions,uploadPath2} from '@/api/area'
import { listinfo } from '@/api/info'
import Pagination from '@/components/Pagination'
import moment from 'moment'
import { tableColor, titleColor,buttonColor,exportColor} from '@/filters/index'
import { getToken } from '@/utils/auth'
import { listRoom } from '@/api/room'
import LabDialog from '@/components/LabDialog'
import EquipmentInfoDialog from '@/components/EquipmentInfoDialog'
import { getApiUrl } from "@/utils/request";
const statusMap = {
  0: '运行',
  1: '待保养',
  2: '待维修'
}

const foldwayMap = {
  0: '平均年限法',
  1: '不计提折旧'
}

export default {
  name: 'TmpEquipmentInv',
  components: { Pagination, LabDialog,EquipmentInfoDialog },
  filters: {
    statusFilter(type) {
      return statusMap[type]
    },
    foldwayFilter(type) {
      return foldwayMap[type]
    }
  },
  data() {
    return {
      exportColor,
      uploadVisible: false,
      buttonColor,
      uploadPath,
      uploadPath2,
      downUrl: null,
      equipmentInfoVisible: false,
      getFsiteNo:null,
      selectListlab:[],
      searchListlab: [],
      listLoadingSearchlab: true,
      totalSearchlab: 0,
      listQuerySearchlab: {
        page: 1,
        limit: 20,
        fpointName: undefined,
        sort: 'create_time',
        order: 'desc'
      },

      searchFlaglab:'',
      labFlag:null,
      searchVisiblelab: false,
      labDialogFsiteNo:null,

      fstateOptions: null,
      getListfclassstno: null,
      getListfequipmenttype: null,
      getListfsiteNo: null,
      getListfpointNo: null,
      getListfpointNoQuery: null,
      getListfpointNoAll: null,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        fstate: undefined,
        fsiteNo: undefined,
        feuipmentid: undefined,
        fequipmenttag: undefined,
        fpointNo: undefined,
        fpointSize: undefined,
        finstalldate: undefined,
        fequipmenttype: undefined,
        fequipmentbarcode: undefined,
        sort: 'create_time',
        order: 'desc'
      },
      searchListAll: [],
      searchList: [],
      searchVisible: false,
      totalSearch: 0,
      listLoadingSearch: true,
      listQuerySearch: {
        page: 1,
        limit: 20,
        fequipmentno: undefined,
        sort: 'create_time',
        order: 'desc'
      },
      foldwayOptions: [
        {
          value: 0,
          label: '平均年限法'
        },
        {
          value: 1,
          label: '不计提折旧'
        }
      ],
      dataForm: {
        fsiteNo: undefined,
        feuipmentid: undefined,
        fequipmenttag: undefined,
        fspec: undefined,
        fpointNo: undefined,
        fpointSize: undefined,
        finstalldate: undefined,
        fequipmenttype: undefined,
        fequipmentbarcode: undefined,
        fstate: undefined,
        fmaintaindate: undefined,
        frepairdate: undefined,
        fbuyprice: undefined,
        foldway: undefined,
        foldmoney: undefined,
        flastrate: undefined,
        flastmoney: undefined,
        flosdate: undefined,
        fvideourl: undefined,
        fmacno: undefined,
        fsupno: undefined,
        flinkmac: undefined,
        flinkmark: undefined,
        fip: undefined,
        fport: undefined,
        fcolor: undefined,
        id: undefined
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      tableColor: tableColor,
      titleColor: titleColor,
      rules: {
        fsiteNo: [{ required: true, message: '用户编号不能为空' }],
        feuipmentid: [{ required: true, message: '设备编号不能为空' }],
        fstate: [{ required: true, message: '设备状态不能为空' }],
        // fpointNo: [{ required: true, message: '存放地点不能为空' }],
        // fpointSize: [{ required: true, message: '存放位置不能为空' }],
        fequipmentbarcode: [{ required: true, message: '固定资产码不能为空' }]
      }
    }
  },
  computed: {
    headers() {
      return {
        Authorization: getToken()
      }
    }
  },
  created() {
    this.downUrl = getApiUrl() + "xlsx/物料柜.xlsx";

    this.getList()
    // 客户名称
    fsiteOptionsByLevel(3)
      .then(response => {
        this.getListfsiteNo = response.data.data.list
      })
      .catch(() => {
        this.getListfsiteNo = []
      })

    getListArea({ flag: 22 })
      .then(response => {
        this.fstateOptions = response.data.data.list
      })
      .catch(() => {
        this.fstateOptions = []
      })

    if(this.$store.state.user.fsiteLevel==3){
      this.listQuery.fsiteNo = this.$store.state.user.fsiteNo;
      // 存放地点
      getListArea({ flag: 10,arg1:this.$store.state.user.fsiteNo })
        .then(response => {
          this.getListfpointNo = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNo = []
        })
    }else{
      // 存放地点
      getListArea({ flag: 10 })
        .then(response => {
          this.getListfpointNo = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNo = []
        })
    }

    // 全部设备列表
    listinfo()
      .then(response => {
        this.searchListAll = response.data.data.list
      })
      .catch(() => {
        this.searchListAll = []
      })

  },
  methods: {
    formatfsiteNo: function(row, column) {
      if (this.getListfsiteNo) {
        for (let i = 0; i < this.getListfsiteNo.length; i++) {
          if (row.fsiteNo === this.getListfsiteNo[i].value) {
            return this.getListfsiteNo[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    handleClose(done){
      this.listQuerySearchlab.page=1
      done()
    },
    fsiteNoChange(data){
      this.dataForm.fpointNo=''
      this.searchListlab=[]
      this.getListfpointNo = []
      if(data){
        this.getFsiteNo=data
        this.getSearchListlab(data)
        getPointOptions(data)
      .then(response => {
        this.getListfpointNo = response.data.data.list
      })
      .catch(() => {
        this.getListfpointNo = []
      })
      }
    },
    // 设备信息弹出框
    searchDialogEequipmentInfo() {
      this.equipmentInfoVisible = true
    },
    // 设备信息弹出框
    equipmentInfoDialogValue(value){
      this.dataForm.feuipmentid = value.info.feuipmentid
      this.dataForm.fequipmenttag = value.info.fequipmentname
      this.dataForm.fspec = value.info.fspec

      getFequipmentbarcode({ feuipmentid: value.info.fequipmenttype })
        .then((response) => {
          if (response) {
            this.dataForm.fequipmentbarcode = response.data.data
          }
        })
        .catch(() => {
          this.dataForm.fequipmentbarcode = ''
        })

    },
    fsiteNoQueChange(data){
      this.listQuery.fpointNo=''
      this.searchListlab=[]
      this.getListfpointNoQuery = []

      if(data){
        this.getFsiteNo=data
        getPointOptions(data)
      .then(response => {
        this.getListfpointNoQuery = response.data.data.list
      })
      .catch(() => {
        this.getListfpointNoQuery = []
      })
      }

    },
    // 地点获取搜索列表
    getSearchListlab(data) {
      this.listLoadingSearchlab = true
      if(data){
        const temp = {
        fsiteNo:data,
        fpointFlag:4,
        page:this.listQuerySearchlab.page,
        limit:this.listQuerySearchlab.limit,
        sort: 'create_time',
        order: 'desc',
        fpointName:this.listQuerySearchlab.fpointName,
      }
       listRoom(temp)
      .then(response => {
        this.searchListlab = response.data.data.list
        this.totalSearchlab = response.data.data.total
          this.listLoadingSearchlab = false
      })
      .catch(() => {
        this.searchListlab = []
        this.totalSearchlab = 0
          this.listLoadingSearchlab = false
      })
      }else{
        this.searchListlab = []
      }
    },

    // 地点获取搜索列表
    getSearchListlabPage(data) {
      this.listLoadingSearchlab = true
      let queryFsiteNo
      if(data){
        if(this.searchFlaglab==='add'){
         // queryFsiteNo = this.dataForm.fsiteNo
         queryFsiteNo = this.$store.state.user.fsiteNo
        }else{
          // queryFsiteNo = this.listQuery.fsiteNo
          queryFsiteNo = this.$store.state.user.fsiteNo
        }
        const temp = {
        fsiteNo:queryFsiteNo,
        fpointFlag:4,
        page:this.listQuerySearchlab.page,
        limit:this.listQuerySearchlab.limit,
        sort: 'create_time',
        order: 'desc',
        fpointName:this.listQuerySearchlab.fpointName,
      }
       listRoom(temp)
      .then(response => {
        this.searchListlab = response.data.data.list
        this.totalSearchlab = response.data.data.total
          this.listLoadingSearchlab = false
      })
      .catch(() => {
        this.searchListlab = []
        this.totalSearchlab = 0
          this.listLoadingSearchlab = false
      })
      }else{
        this.searchListlab = []
      }
    },


    // 地点获取搜索列表
    searchFilterlab() {
      this.listQuerySearchlab.page = 1
      this.getSearchListlab(this.getFsiteNo)
    },
    // 地点获取搜索列表
    searchDatalab(row) {
      this.searchVisiblelab = false
      this.listQuerySearchlab.page = 1
      if(this.searchFlaglab==='add'){
      this.dataForm.fpointNo = row.fpointNo
      }else{
        this.listQuery.fpointNo = row.fpointNo
      }
    },

    // 搜索地点弹出框
    searchDialoglab(value) {
      this.labFlag = value
      if(value === 'add'){
        this.labDialogFsiteNo = this.dataForm.fsiteNo
      }else{
        this.labDialogFsiteNo = this.listQuery.fsiteNo
      }
      this.searchVisiblelab = true
    },

    // 地点弹出框返回值
    labDialogValue(value){
      if(this.labFlag==='add'){
        this.dataForm.fpointNo = value.lab.fpointNo
      }else{
        this.listQuery.fpointNo = value.lab.fpointNo
      }
    },

    // 搜索地点获取焦点
    fpointNoFocus(){
       if(!this.listQuery.fsiteNo){
          this.getListfpointNoQuery = []
        }
    },

    // 存放地点
    formatfpointNo: function(row, column) {
      if (this.getListfpointNoAll) {
        for (let i = 0; i < this.getListfpointNoAll.length; i++) {
          if (row.fpointNo === this.getListfpointNoAll[i].value) {
            return this.getListfpointNoAll[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    datetimeFormat(row, column) {
      const date = row[column.property]
      if (date === undefined || date === null) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD')
    },
    uploadFileSuccess: function(response) {
      this.uploadVisible = false;
      this.$notify.success({
        title: '导入',
        message: response.data
      })
    },
    handleUpload() {
      this.uploadVisible = true;
    },

    // 设备类型
    equipmenttype: function(fequipmenttype) {
      if (this.getListfequipmenttype.length > 0) {
        for (let i = 0; i < this.getListfequipmenttype.length; i++) {
          if (fequipmenttype === this.getListfequipmenttype[i].value) {
            return this.getListfequipmenttype[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
      // 设备类型回显
    formatfequipmenttype: function(row) {
      if (this.searchListAll.length > 0) {
        for (let i = 0; i < this.searchListAll.length; i++) {
          if (row.feuipmentid === this.searchListAll[i].feuipmentid) {
            return this.equipmenttype(this.searchListAll[i].fequipmenttype)
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 编辑设备类型回显
    formatfetype: function(row) {
       console.log('row',row);
        console.log('this.searchListAll',this.searchListAll);
      if (this.searchListAll.length > 0) {
        for (let i = 0; i < this.searchListAll.length; i++) {
          if (row.feuipmentid === this.searchListAll[i].feuipmentid) {
            return this.searchListAll[i].fequipmenttype
          }
        }
        return ''
      } else {
        return ''
      }
    },

    // 型号回显
    formatfspec(row){
       console.log('row',row);
        console.log('this.searchListAll',this.searchListAll);
      if (this.searchListAll.length > 0) {

        for (let i = 0; i < this.searchListAll.length; i++) {
          if (row === this.searchListAll[i].feuipmentid) {
            return this.searchListAll[i].fspec
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 设备分类
    formatfclassstno: function(row, column) {
      if (this.getListfclassstno.length > 0) {
        for (let i = 0; i < this.getListfclassstno.length; i++) {
          if (row.fclassstno === this.getListfclassstno[i].value) {
            return this.getListfclassstno[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 设备状态
    formatfstate: function(row, column) {
      if (this.fstateOptions.length > 0) {
        for (let i = 0; i < this.fstateOptions.length; i++) {
          if (row.fstate === this.fstateOptions[i].value) {
            return this.fstateOptions[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },

    // 搜索弹出框
    searchDialog() {
      this.searchVisible = true
    },

    // 搜索过滤
    searchFilter() {
      this.listQuerySearch.page = 1
      this.getSearchList()
    },

    // 搜索数据
    searchData(row) {
      this.searchVisible = false
      this.dataForm.feuipmentid = row.feuipmentid
      this.dataForm.fequipmentname = row.fequipmentname
      this.dataForm.fequipmenttag = row.fequipmentname
      this.dataForm.fclassstno = row.fclassstno
      this.dataForm.fequipmenttype = row.fequipmenttype
      this.dataForm.funit = row.funit
      this.dataForm.fspec = row.fspec
      this.dataForm.fuseyear = row.fuseyear

    getFequipmentbarcode({ feuipmentid: row.fequipmenttype })
        .then((response) => {
          if (response) {
            this.dataForm.fequipmentbarcode = response.data.data
          }
        })
        .catch(() => {
          this.dataForm.fequipmentbarcode = ''
        })

    },

    // 设备信息列表
    getSearchList() {
      this.listLoadingSearch = true
      listinfo(this.listQuerySearch)
        .then(response => {
          this.searchList = response.data.data.list
          this.totalSearch = response.data.data.total
          this.listLoadingSearch = false
        })
        .catch(() => {
          this.searchList = []
          this.totalSearch = 0
          this.listLoadingSearch = false
        })
    },

    getList() {
      this.listLoading = true
      this.listQuery.fequipmenttype = 14
      listequipmentInv(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        fsiteNo: undefined,
        feuipmentid: undefined,
        fequipmenttag: undefined,
        fpointNo: undefined,
        fpointSize: undefined,
        finstalldate: undefined,
        fequipmenttype: undefined,
        fequipmentbarcode: undefined,
        fstate: undefined,
        fmaintaindate: undefined,
        frepairdate: undefined,
        fbuyprice: undefined,
        foldway: undefined,
        foldmoney: undefined,
        flastrate: undefined,
        flastmoney: undefined,
        flosdate: undefined,
        fvideourl: undefined,
        fmacno: undefined,
        fsupno: undefined,
        flinkmac: undefined,
        flinkmark: undefined,
        fip: undefined,
        fport: undefined,
        fcolor: undefined,
        id: undefined
      }
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dataForm.fsiteNo = this.$store.state.user.fsiteNo
      /*if (this.list.length > 0) {
        // this.dataForm.fsiteNo = this.list[0].fsiteNo
        this.dataForm.fsiteNo = this.$store.state.user.fsiteNo
        this.getSearchListlab(this.list[0].fsiteNo)
        getPointOptions(this.list[0].fsiteNo)
        .then(response => {
          this.getListfpointNo = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNo = []
        })
        this.getFsiteNo=this.list[0].fsiteNo
      }
      if (this.fstateOptions.length > 0) {
        this.dataForm.fstate = this.fstateOptions[0].value
      }*/
      this.dialogFormVisible = true
      debugger
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          this.dataForm.fequipmenttype = 14
          createequipmentInv(this.dataForm)
            .then((response) => {
              this.list.unshift(response.data.data)
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '添加设备台帐成功'
              })
            })
            .catch((response) => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row)
      this.getSearchListlab(row.fsiteNo)
      getPointOptions(row.fsiteNo)
      .then(response => {
        this.getListfpointNo = response.data.data.list
      })
      .catch(() => {
        this.getListfpointNo = []
      })
      this.dataForm.fequipmenttype= this.formatfetype(row)
      this.dataForm.fspec= this.formatfspec(row.feuipmentid)

      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          this.dataForm.fequipmenttype = 14
          updateequipmentInv(this.dataForm, this.$route.query.id)
            .then(() => {
              for (const v of this.list) {
                if (v.fequipmentbarcode === this.dataForm.fequipmentbarcode) {
                  const index = this.list.indexOf(v)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新设备台帐成功'
              })
            })
            .catch((response) => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除设备台账', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteequipmentInv(row)
          .then((response) => {
            this.$notify.success({
              title: '成功',
              message: '删除设备台账成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch((response) => {
            this.$notify.error({
              title: '失败',
              message: response
            })
          })
      })
    },
    indexMethod(index) {
      index = index + 1
      return index
    }
  }
}
</script>
